package col

import (
	"yunj/pkg/yunj/core/builder/builderconsts"
	tableConsts "yunj/pkg/yunj/core/builder/builderconsts"
	"yunj/pkg/yunj/core/builder/table"
)

// 复选框列
type Checkbox struct {
	table.Col
}

func NewCheckbox(field string, title ...string) *Checkbox {
	c := &Checkbox{}
	// 设置默认值
	c.Type = tableConsts.TABLE_COL_TYPE_CHECKBOX

	table.SetColInstance(&c.Col, c)
	c.SetColField(field)
	if len(title) > 0 {
		c.SetTitle(title[0])
	}
	return c
}

// 设置标题
func (c *Checkbox) SetTitle(title string) *Checkbox {
	c.Title = title
	return c
}

// 设置排列方式
func (c *Checkbox) SetAlign(align string) *Checkbox {
	c.Align = align
	return c
}

// 设置固定列
func (c *Checkbox) SetFixed(fixed string) *Checkbox {
	c.Fixed = fixed
	return c
}

// 设置隐藏列
func (c *Checkbox) SetHide(hide string) *Checkbox {
	c.Hide = hide
	return c
}

// 设置宽度
func (c *Checkbox) SetWidth(width any) *Checkbox {
	c.Width = width
	return c
}

// 设置最小宽度
func (c *Checkbox) SetMinWidth(minWidth uint64) *Checkbox {
	c.MinWidth = minWidth
	return c
}

// 设置最大宽度
func (c *Checkbox) SetMaxWidth(maxWidth uint64) *Checkbox {
	c.MaxWidth = maxWidth
	return c
}

// 设置权限
func (c *Checkbox) SetAuth(auth string) *Checkbox {
	c.Auth = auth
	return c
}

// 处理属性
func (c *Checkbox) HandleAttr() error {
	if c.Align == "" {
		c.Align = builderconsts.ALIGN_CENTER
	}
	if c.Fixed == "" {
		c.Fixed = tableConsts.TABLE_COL_FIXED_LEFT
	}
	return nil
}
